package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.PrivacySettingCon;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.PrivacySettingPresenter;
import com.ninetaildemonfox.zdl.socialproject.utils.dialog.DialogPayActivity;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/24 15:34
 * 功能描述： 隐私设置
 * 联系方式：1037438704@qq.com
 */
public class PrivacySettingActivity extends BaseActivity implements PrivacySettingCon {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.image_list)
    ImageView imageList;
    @BindView(R.id.image_distance)
    ImageView imageDistance;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_pay)
    TextView textPay;
    @BindView(R.id.text_open)
    TextView textOpen;
    private Drawable drawable, drawable2;
    private PrivacySettingPresenter presenter;
    private String set_info = "1";
    private String boolean1 = "1";
    private int set_hidden_distance = 1;
    private String set_info_money;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_privacy_setting;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        textCenter.setText("隐私设置");
        textRight.setText("保存");
        textRight.setVisibility(View.VISIBLE);
        imageleftFinish.setVisibility(View.VISIBLE);
        presenter = new PrivacySettingPresenter(me, this);
        presenter.getSystemSet(token, "", "", "", "", "1");
    }

    @OnClick({R.id.image_left_finish, R.id.text_pay, R.id.text_right, R.id.text_open, R.id.image_list, R.id.image_distance})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_right:
                //保存
                WaitDialog.show(me, "");
//                set_info	个人详情设置1公开 2相册解锁查看	否	文本	未提供
//                set_hidden_list	公园列表隐身 1否 2是	否	文本	未提供
//                set_hidden_distance	对他人隐藏我的距离 1否 2是	否	文本	未提供
//                set_info_money	解锁相册所需金额【非必填】
                presenter.getSystemSet(token, set_info, boolean1 + "", set_hidden_distance + "", set_info_money + "", "2");
                break;
            case R.id.text_pay:
                String textpay = "";
                if (getSex.equals("1")) {
                    textpay = "所有女士必须付费才能查看你的相册，费用由你决定，这可能会降低你的访问量";
                } else {
                    textpay = "所有男士必须付费才能查看你的相册，费用由你决定，这可能会降低你的访问量";
                }
                MessageDialog.show(me, "", textpay, "确认", "取消")
                        .setOnOkButtonClickListener(new OnDialogButtonClickListener() {
                            @Override
                            public boolean onClick(BaseDialog baseDialog, View v) {
                                startActivityForResult(new Intent(me, DialogPayActivity.class), 1);
                                return false;
                            }
                        }).setCancelable(false).show();
                break;
            case R.id.text_open:
                set_info = "1";
                drawable = getResources().getDrawable(R.mipmap.ic_garden_true);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                textOpen.setCompoundDrawables(null, null, drawable, null);

                drawable2 = getResources().getDrawable(R.mipmap.ic_garden_false);
                drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight());
                textPay.setCompoundDrawables(null, null, drawable2, null);
                break;
            case R.id.image_list:
                if (boolean1.equals("1")) {
                    boolean1 = "2";
                    imageList.setImageResource(R.mipmap.icon_voice_true);
                } else {
                    boolean1 = "1";
                    imageList.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
                }
                break;
            case R.id.image_distance:
                if (set_hidden_distance == 1) {
                    set_hidden_distance = 2;
                    imageDistance.setImageResource(R.mipmap.icon_voice_true);
                } else {
                    set_hidden_distance = 1;
                    imageDistance.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
                }
                break;
            default:
        }
    }

    //结果处理函数，当从secondActivity中返回时调用此函数
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {
            Bundle bundle = data.getExtras();
            String moeny = bundle.getString("money");
            set_info_money = moeny;
            textPay.setText("相册付费查看（" + set_info_money + "元）");
            drawable = getResources().getDrawable(R.mipmap.ic_garden_true);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textPay.setCompoundDrawables(null, null, drawable, null);

            drawable2 = getResources().getDrawable(R.mipmap.ic_garden_false);
            drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight());
            textOpen.setCompoundDrawables(null, null, drawable2, null);
            set_info = "2";
        }
    }

    @Override
    public void Success(Map<String, String> data) {
//        "set_info": "1",   //  个人详情设置 1公开 2相册解锁查看
//                "set_info_money": "0",    // 相册解锁所需金额
//                "set_hidden_list": "1",   公园列表隐身 1否 2是
//        "set_hidden_distance": "1"   //  对他人隐藏我的距离 1否 2是

        set_info = data.get("set_info");
        if (set_info.equals("1")) {
            drawable = getResources().getDrawable(R.mipmap.ic_garden_true);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textOpen.setCompoundDrawables(null, null, drawable, null);

            drawable2 = getResources().getDrawable(R.mipmap.ic_garden_false);
            drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight());
            textPay.setCompoundDrawables(null, null, drawable2, null);
        } else {
            drawable = getResources().getDrawable(R.mipmap.ic_garden_true);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            textPay.setCompoundDrawables(null, null, drawable, null);

            drawable2 = getResources().getDrawable(R.mipmap.ic_garden_false);
            drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight());
            textOpen.setCompoundDrawables(null, null, drawable2, null);
            // 相册解锁所需金额
            set_info_money = data.get("set_info_money");
            textPay.setText("相册付费查看（" + set_info_money + "元）");
        }


//        "set_hidden_list": "1",   公园列表隐身 1否 2是
        boolean1 = data.get("set_hidden_list");
        if (boolean1.equals("1")) {
            imageList.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
        } else {
            imageList.setImageResource(R.mipmap.icon_voice_true);
        }
        //        "set_hidden_distance": "1"   //  对他人隐藏我的距离 1否 2是
        if (!TextUtils.isEmpty(data.get("set_hidden_distance"))) {
            set_hidden_distance = Integer.valueOf(data.get("set_hidden_distance"));
            if (data.get("set_hidden_distance").equals("1")) {
                imageDistance.setImageResource(R.mipmap.icon_voice_broadcast_declaration);
            } else {
                imageDistance.setImageResource(R.mipmap.icon_voice_true);
            }
        }
    }

    @Override
    public void Failed(String msg) {

    }

    @Override
    public void showLoading() {

    }
}
